package com.vercon.moensmart.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.vercon.common.Constants;
import com.vercon.moensmart.MainApplication;
import com.vercon.moensmart.mode.MenuStateBean;

/**
 * Created by Kuson on 17/5/28.
 */

public class PreferenceUtils {

    public static final String device_name = "device_name";//设备名称

    public static final String home_menu = "home_menu";//首页菜单栏按钮
    public static final String default_menu = "default_menu";//应用中心菜单栏按钮
    public static final String unit_set = "unit_set";//设置温度单位
    public static final String city_name = "city_name";//定位城市名称
    public static final String DataBean = "RowsBean";//定位城市数据
    public static final String city_code = "city_code";//定位城市编码

    public static final String weather_one_call = "weather_one_call";//天气详情
    public static final String weather_one_call_new = "weather_one_call_new";//天气详情
    public static final String weather_lift = "weather_lift";//生活指数
    public static final String weather_pollution = "weather_pollution";//天气污染
//    public static final String weather_current = "weather_current";//实时天气数据
    public static final String Weather_warning = "Weather_warning";//保存天气预警数据

    public final static String CUSTOM_FAT = "custom_fat";//自定义体质称
    public final static String CUSTOM_SKIN = "custom_skin";//自定义测肤仪
    public final static String CUSTOM_BRUSH = "custom_brush";//自定义刷牙
    public final static String CUSTOM_ALARM_BRUSH = "custom_alarm_brush";//自定义计时器刷牙
    public final static String CUSTOM_ALARM_WASHFACE = "custom_alarm_washface";//自定义计时器洁面
    public final static String CUSTOM_ALARM_TOILET = "custom_alarm_toilet";//自定义计时器蹲坑
    public final static String CUSTOM_ALARM_FACIALMASK = "custom_alarm_facialmask";//自定义计时器敷面膜
    public final static String CUSTOM_ALARM_TAKEBATH = "custom_alarm_takebath";//自定义计时器洗澡

    public final static String MenuState = "MenuState";//下拉菜单状态保存
    public final static String VolumeData = "volumeData_volume";//下音量保存
    public final static String fliqlo_timer = "fliqlo_timer";//屏保定时时间
    public final static String Brush_study = "Brush_study";//是否弹出学习弹窗
    public final static String Brush_hint = "Brush_hint";//口腔提示信息
    public final static String isnowactivate_showguide = "isnowactivate_showguide";//用户引导
    public final static String user_id = "";//选择的用户id

    public static void setClearAll() {
        setFliqloTimer(Constants.tab_fliqlo_timer_num,-1);
        setData(device_name,"");
        setData(home_menu,null);
        setData(DataBean,null);
        setData(city_code,"");
        setData(weather_one_call_new,"");
        setData(weather_lift,"");
        setData(weather_pollution,"");
        setData(Weather_warning,null);
        setData(MenuState,null);
        setData(VolumeData,0);
        setData(Brush_study,false);
        setData(Brush_hint,null);
        setData(default_menu,null);
        setSleepData(Constants.sleep_num, -1);
        setSleepData(Constants.screen_num, -1);
        setData(PreferenceUtils.CUSTOM_ALARM_BRUSH,false);
        setData(PreferenceUtils.CUSTOM_ALARM_TOILET,false);
        setData(PreferenceUtils.CUSTOM_ALARM_WASHFACE,false);
        setData(PreferenceUtils.CUSTOM_ALARM_FACIALMASK,true);
        setData(PreferenceUtils.CUSTOM_ALARM_TAKEBATH,false);
        setData(PreferenceUtils.isnowactivate_showguide,true);
    }

    /**
     * 保存数据
     */
    public static void setData(String key, String value) {
        getPreference(MainApplication.Companion.getContext()).edit().putString(key, value).apply();
    }
    /**
     * 保存数据
     */
    public static void setData(String key, boolean value) {
        getPreference(MainApplication.Companion.getContext()).edit().putBoolean(key, value).apply();
    }
    /**
     * 保存数据
     */
    public static void setData(String key, int value) {
        getPreference(MainApplication.Companion.getContext()).edit().putInt(key, value).apply();
    }

    public static void setData(String key, Object value) {
        getPreference(MainApplication.Companion.getContext()).edit().putString(key, new Gson().toJson(value)).apply();
    }

    /**
     * 获取数据
     *
     * @param key
     * @return
     */
    public static String getData(String key) {
        return getPreference(MainApplication.Companion.getContext()).getString(key, "");
    }

    public static boolean getBooleanData(String key) {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(key, true);
    }

    public static int getVolumeData() {
        return getPreference(MainApplication.Companion.getContext()).getInt(VolumeData, 0);
    }

    public static void setSleepData(String key, int value) {
        getPreference(MainApplication.Companion.getContext()).edit().putInt(key, value).apply();
    }

    public static int getSleepData(String key) {
        return getPreference(MainApplication.Companion.getContext()).getInt(key, -1);
    }

    //获取默认温度单位
    public static String getUnitsData(String key) {
        return getPreference(MainApplication.Companion.getContext()).getString(key, Constants.UNITS_METRIC);
    }

    //获取城市名称
    public static String getCityName(String key) {
        return getPreference(MainApplication.Companion.getContext()).getString(key, "GuangZhou");
    }

    public static SharedPreferences getPreference(Context context) {
        return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
    }

    public static boolean getCustomFat() {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(CUSTOM_FAT,true);
    }

    public static boolean getCustomSkin() {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(CUSTOM_SKIN,true);
    }

    public static boolean getCustomBrush() {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(CUSTOM_BRUSH,true);
    }



    public static void setFliqloTimer(String key, int value) {
        getPreference(MainApplication.Companion.getContext()).edit().putInt(key, value).apply();
    }

    public static int getFliqloTimer(String key) {
        return getPreference(MainApplication.Companion.getContext()).getInt(key, -2);
    }
    public static boolean getBrush_study() {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(Brush_study,false);
    }

    public static boolean getIsnowactivate_showguide() {
        return getPreference(MainApplication.Companion.getContext()).getBoolean(isnowactivate_showguide,true);
    }

    public static MenuStateBean getMenuState() {
        MenuStateBean bean = new Gson().fromJson(getPreference(MainApplication.Companion.getContext()).getString(MenuState,null), MenuStateBean.class);
        return  bean;
    }
}
